package com.haidechizi.i18n.code.generator.common.message.language;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class LanguageHelper {

    /**
     * 通过前端选择的语言，构建Language
     *
     * @param languageType
     * @return
     */
    public static List<Language> getLanguageList(List<String> languageType) {
        return languageType.stream().map(LanguageHolder::getLanguage).filter(Objects::nonNull).collect(Collectors.toList());
    }


    /**
     * 翻译成对应的语言
     *
     * @param languageList
     * @param key
     * @param cnData
     * @param languageMap
     */
    public static void generateLanguage(List<Language> languageList, String key, String cnData, Map<String, Map<String, String>> languageMap) {
        languageList.forEach(language -> {
            language.generateLanguage(key, cnData, languageMap);
        });
    }


    /**
     * 翻译成对应的语言
     *
     * @param languageList
     * @param languageMap
     */
    public static Map<String, Map<String, String>> batchGenerateLanguage(String currentLanguage, List<Language> languageList, Map<String, String> languageMap) {
        Map<String, Map<String, String>> result = new HashMap<>();
        languageList.forEach(language -> {
            Map<String, String> singleMap = language.batchGenerateLanguage(currentLanguage,languageMap);
            result.put(language.type(), singleMap);
        });
        return result;
    }


}
